package com.wans.guli.product.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Validator;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wans.guli.common.utils.R;
import com.wans.guli.product.constant.em.ProductAttrValueQuickShowEnum;
import com.wans.guli.product.constant.em.SpuPublishStatusEnum;
import com.wans.guli.product.entity.*;
import com.wans.guli.product.feign.CouponFeignClient;
import com.wans.guli.product.feign.SearchFeignClient;
import com.wans.guli.product.feign.WareFeignClient;
import com.wans.guli.product.feign.vo.*;
import com.wans.guli.product.service.*;
import com.wans.guli.product.vo.SpuInfoItemVO;
import com.wans.guli.product.vo.spu.save.Image;
import com.wans.guli.product.vo.spu.save.SpuSaveRestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wans.guli.common.utils.PageUtils;
import com.wans.guli.common.utils.Query;

import com.wans.guli.product.dao.SpuInfoDao;
import org.springframework.transaction.annotation.Transactional;


@Service("spuInfoService")
@SuppressWarnings("all")
public class SpuInfoServiceImpl extends ServiceImpl<SpuInfoDao, SpuInfoEntity> implements SpuInfoService {

    @Autowired
    private SpuInfoDescService spuInfoDescService;
    @Autowired
    private SpuInfoService spuInfoService;
    @Autowired
    private ProductAttrValueService productAttrValueService;
    @Autowired
    private SkuSaleAttrValueService skuSaleAttrValueService;
    @Autowired
    private SkuImagesServiceImpl skuImagesService;
    @Autowired
    private SpuImagesServiceImpl spuImagesService;
    @Autowired
    private AttrServiceImpl attrService;
    @Autowired
    private CouponFeignClient couponFeignClient;
    @Autowired
    private SkuInfoServiceImpl skuInfoService;
    @Autowired
    private WareFeignClient wareFeignClient;
    @Autowired
    private BrandServiceImpl brandService;
    @Autowired
    private CategoryServiceImpl categoryService;
    @Autowired
    private SearchFeignClient searchFeignClient;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        List<String> eqKeys = Arrays.asList("catelogId", "brandId", "status");
        HashMap<String, String> eqMap = new HashMap<>();
        params.keySet().stream()
                .filter(key -> params.get(key) != null && !Objects.equals(params.get(key), "") && !"0".equals(params.get(key)))
                .filter(key -> eqKeys.contains(key)).forEach(key -> eqMap.put(key.replace("catelogId", "catalog_id").replace("I", "_i").replace("status", "publish_status"), params.get(key).toString().trim()));

        // 排序字段
        String sidx = (String) params.get("sidx");
        boolean sidxEmpty = sidx == null;
        if (sidxEmpty)
            sidx = "id";
        LambdaQueryWrapper<SpuInfoEntity> lambdaQueryWrapper = new QueryWrapper<SpuInfoEntity>().allEq(eqMap).orderBy(!sidxEmpty, sidx.equals("asc"), sidx).lambda();
        if (((String) params.get("key")) != null && ((String) params.get("key")).length() > 0) {
            // 如果 关键字 字段都不为空 那就模糊查询
            lambdaQueryWrapper.like(SpuInfoEntity::getSpuName, ((String) params.get("key")).trim());
            lambdaQueryWrapper.or().like(SpuInfoEntity::getSpuDescription, ((String) params.get("key")).trim());

        }
        IPage<SpuInfoEntity> page = this.page(new Query<SpuInfoEntity>().getPage(params), lambdaQueryWrapper);

        return new PageUtils(page);
    }

    /**
     * 保存商品信息
     *
     * @param saveRestVO 保存商品信息的视图
     */
    @Override
    @Transactional
    public void saveSpuInfo(SpuSaveRestVO saveRestVO) {
        //1、保存spu基本信息 pms_spu_info
        SpuInfoEntity spuInfoEntity = BeanUtil.copyProperties(saveRestVO, SpuInfoEntity.class);
        // 设置时间
        spuInfoEntity.setCreateTime(new Date());
        spuInfoEntity.setUpdateTime(new Date());
        boolean saveSpuBaseInfo = spuInfoService.save(spuInfoEntity);
        if (!saveSpuBaseInfo) throw new RuntimeException("保存spu商品基本信息失败");
        //2、保存Spu的描述图片 pms_spu_info_desc
        SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
        StringJoiner decriptImageUrls = new StringJoiner(";");
        saveRestVO.getDecript().forEach(decript -> decriptImageUrls.add(decript.trim()));
        // 设置描述信息
        spuInfoDescEntity.setDecript(decriptImageUrls.toString());
        // 设置spuId - 商品
        spuInfoDescEntity.setSpuId(spuInfoEntity.getId());
        boolean saveSpuInfoDesc = spuInfoDescService.save(spuInfoDescEntity);
        if (!saveSpuInfoDesc) throw new RuntimeException("保存spu商品描述信息图片URL失败");
        //3、保存spu的图片集 pms_spu_images
        Collection<SpuImagesEntity> spuImagesEntities = saveRestVO.getImages().stream().map(image -> {
            SpuImagesEntity spuImagesEntity = new SpuImagesEntity();
            image = image.trim();
            String imageName = image.substring(image.lastIndexOf("_") + 1);
            spuImagesEntity.setImgUrl(image);
            spuImagesEntity.setImgName(imageName);
            // 设置spuId
            spuImagesEntity.setSpuId(spuInfoEntity.getId());
            // 前端没有设置该字段，默认为0
            spuImagesEntity.setDefaultImg(0);
            return spuImagesEntity;
        }).collect(Collectors.toList());
        boolean saveSpuImages = spuImagesService.saveBatch(spuImagesEntities);
        if (!saveSpuImages) throw new RuntimeException("保存spu商品图片信息失败");
        //4、保存spu的规格参数 pms_product_attr_value
        List<ProductAttrValueEntity> productAttrValueEntities = saveRestVO.getBaseAttrs().stream().map(attr -> {
            ProductAttrValueEntity productAttrValueEntity = new ProductAttrValueEntity();
            // 通过id查询 属性
            AttrEntity attrEntity = attrService.lambdaQuery().eq(AttrEntity::getAttrId, attr.getAttrId()).one();
            if (attrEntity == null) throw new RuntimeException("保存spu商品属性信息失败 - 恶意刷接口");
            // 拼装商品属性信息
            // 商品id
            productAttrValueEntity.setSpuId(spuInfoEntity.getId());
            productAttrValueEntity.setAttrName(attrEntity.getAttrName());
            // TODO 商品属性顺序设置
            productAttrValueEntity.setAttrSort(0);
            productAttrValueEntity.setAttrId(attr.getAttrId());
            productAttrValueEntity.setAttrValue(attr.getAttrValues());
            productAttrValueEntity.setQuickShow(attr.getShowDesc().intValue());

            return productAttrValueEntity;
        }).collect(Collectors.toList());
        boolean saveProductAttrValue = productAttrValueService.saveBatch(productAttrValueEntities);
        if (!saveProductAttrValue) throw new RuntimeException("保存商品属性失败");
        //5、保存spu的积分信息 gulimall_sms -> sms_spu_bounds
        SpuBoundsRestVO spuBounds = new SpuBoundsRestVO();
        // 拷贝Bound两个属性
        BeanUtil.copyProperties(saveRestVO.getBounds(), spuBounds);
        // 设置spuId
        spuBounds.setSpuId(spuInfoEntity.getId());
        // 调用远程保存 - 同步调用
        R saveSpuBounds = couponFeignClient.save(spuBounds);
        if (!saveSpuBounds.get("code").toString().equals("0")) throw new RuntimeException("保存积分信息失败");


        //保存当前spu对应的所有sku信息;
        // 1)、sku的基本信息 pms_sku_info
        saveRestVO.getSkus().forEach(item -> {
            SkuInfoEntity skuInfoEntity = new SkuInfoEntity();
            // 属性拷贝
            BeanUtil.copyProperties(item, skuInfoEntity);
            // 设置其他属性
            // 设置商品spu id
            skuInfoEntity.setSpuId(spuInfoEntity.getId());
            // 设置分类id
            skuInfoEntity.setCatalogId(saveRestVO.getCatalogId());
            // 设置品牌id
            skuInfoEntity.setBrandId(saveRestVO.getBrandId());
            // 设置描述
            skuInfoEntity.setSkuDesc(item.getDescar().toString());
            // 设置默认图片
            List<Image> images = item.getImages().stream().filter(image -> {
                if (image.getDefaultImg() == 1) skuInfoEntity.setSkuDefaultImg(image.getImgUrl());
                // 过滤掉没有图片路径的sku
                return Validator.isUrl(image.getImgUrl());
            }).collect(Collectors.toList());
            // 过滤掉没有图片路径的sku重新回填回去
            item.setImages(images);
            // 设置销量 初始 0
            skuInfoEntity.setSaleCount(0L);
            // 保存sku - 单独保存
            boolean saveSkuInfo = skuInfoService.save(skuInfoEntity);
            if (!saveSkuInfo) throw new RuntimeException("sku信息保存失败");


            // 2)、sku的图片信息 pms_sku_images
            //TODO 可以在 1 里获取 - 不过目前不考虑性能问题
            List<SkuImagesEntity> skuImagesEntities = new LinkedList<>();
            item.getImages().forEach(image -> {
                SkuImagesEntity skuImagesEntity = new SkuImagesEntity();
                skuImagesEntity.setSkuId(skuInfoEntity.getSkuId());
                skuImagesEntity.setImgUrl(image.getImgUrl());
                skuImagesEntity.setDefaultImg(image.getDefaultImg());
                skuImagesEntity.setImgSort(0);
                skuImagesEntities.add(skuImagesEntity);
            });
            boolean saveSkuImages = skuImagesService.saveBatch(skuImagesEntities);
            if (!saveSkuImages) throw new RuntimeException("保存sku图片信息失败");

            // 3)、sku的销售属性信息 pms_sku_sale_attr_value
            List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = new LinkedList<>();
            item.getAttr().forEach(attr -> {
                SkuSaleAttrValueEntity skuSaleAttrValueEntity = BeanUtil.copyProperties(attr, SkuSaleAttrValueEntity.class);
                // 设置skuId
                skuSaleAttrValueEntity.setSkuId(skuInfoEntity.getSkuId());
                // 设置排序 默认排序
                skuSaleAttrValueEntity.setAttrSort(0);
                skuSaleAttrValueEntities.add(skuSaleAttrValueEntity);
            });
            boolean saveSkuSaleAttrValue = skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);
            if (!saveSkuSaleAttrValue) throw new RuntimeException("保存sku销售属性值失败");

            // 4)、sku的优惠、满减等信息 gulimall_sms->sms_sku_ladder\ sms_sku_full_reduction\ sms_member_price
            SkuLadderRestVO skuLadderRestVO = new SkuLadderRestVO();
            // 设置满减
            BeanUtil.copyProperties(item, skuLadderRestVO);
            // 设置skuId
            skuLadderRestVO.setSkuId(skuInfoEntity.getSkuId());
            // 设置优惠状态 - 是否可以叠加
            skuLadderRestVO.setAddOther(item.getCountStatus());
            // 远程调用优惠券服务
            R saveSkuLadder = couponFeignClient.save(skuLadderRestVO);
            if (!saveSkuLadder.get("code").toString().equals("0"))
                throw new RuntimeException("远程调用优惠券服务失败-saveSkuLadder");

            SkuFullReductionRestVO skuFullReductionRestVO = new SkuFullReductionRestVO();
            // 设置满减
            BeanUtil.copyProperties(item, skuFullReductionRestVO);
            // 设置skuId
            skuFullReductionRestVO.setSkuId(skuInfoEntity.getSkuId());
            // 设置优惠状态 - 是否可以叠加
            skuFullReductionRestVO.setAddOther(item.getPriceStatus());
            R saveSkuFullReduction = couponFeignClient.save(skuFullReductionRestVO);
            if (!saveSkuFullReduction.get("code").toString().equals("0"))
                throw new RuntimeException("远程调用优惠券服务失败-saveSkuFullReduction");

            List<MemberPriceRestVO> memberPriceRestVOList = new LinkedList<>();
            item.getMemberPrice().forEach(itemMemberPrice -> {
                // 封装会员价格
                MemberPriceRestVO memberPriceRestVO = new MemberPriceRestVO();
                memberPriceRestVO.setSkuId(skuInfoEntity.getSkuId());
                memberPriceRestVO.setMemberLevelId(itemMemberPrice.getId());
                memberPriceRestVO.setMemberLevelName(itemMemberPrice.getName());
                memberPriceRestVO.setMemberPrice(itemMemberPrice.getPrice());
                // TODO 先使用 0
                memberPriceRestVO.setAddOther(0);
                memberPriceRestVOList.add(memberPriceRestVO);
            });
            R saveMemberPrices = couponFeignClient.save(memberPriceRestVOList);
            if (!saveMemberPrices.get("code").toString().equals("0"))
                throw new RuntimeException("远程调用优惠券服务失败-saveMemberPrices");

        });

    }


    /**
     * 上架商品
     *
     * @param spuId 商品id
     */
    @Override
    public void upSpuInfoById(Long spuId) {
        // 获取商品信息
        SpuInfoEntity spuInfoEntity = this.getById(spuId);
        if (spuInfoEntity == null) throw new RuntimeException("没有找到对应的商品信息");
        if (spuInfoEntity.getPublishStatus() == SpuPublishStatusEnum.PUBLIC.getPublishStatus())
            throw new RuntimeException("商品已上架");

        // 1)、查出当前spuId对应的所有sku信息
        List<SkuInfoEntity> skuInfoEntities = skuInfoService.lambdaQuery().eq(SkuInfoEntity::getSpuId, spuInfoEntity.getId())
                .list();
        if (skuInfoEntities == null || skuInfoEntities.isEmpty())
            throw new RuntimeException("没有找到对应的sku信息");

        // 2)、对spuId对应的所有属性信息 - pms_product_attr_value表
        List<ProductAttrValueEntity> productAttrValueEntities = productAttrValueService.lambdaQuery()
                .eq(ProductAttrValueEntity::getSpuId, spuId)
                .eq(ProductAttrValueEntity::getQuickShow, ProductAttrValueQuickShowEnum.QUICK_SHOW.getQuickShow())
                .list();
        if (productAttrValueEntities == null || productAttrValueEntities.isEmpty())
            throw new RuntimeException("没有找到对应的属性信息");
        List<SearchSkuEsRestVO.Attr> attrs = productAttrValueEntities.stream().map(
                skuSaleAttrValueEntity -> {
                    SearchSkuEsRestVO.Attr attr = new SearchSkuEsRestVO.Attr();
                    attr.setAttrId(skuSaleAttrValueEntity.getAttrId());
                    attr.setAttrName(skuSaleAttrValueEntity.getAttrName());
                    attr.setAttrValue(skuSaleAttrValueEntity.getAttrValue());
                    return attr;
                }
        ).collect(Collectors.toList());


        // 封装ES Sku信息
        List<SearchSkuEsRestVO> searchSkuEsRestVOS = skuInfoEntities.stream().map(
                skuInfoEntity -> {
                    SearchSkuEsRestVO searchSkuEsRestVO = new SearchSkuEsRestVO();
                    // 封装信息
                    // 属性对拷 先拷贝SkuInfoEntity与SearchSkuEsRestVO共有属性名
                    BeanUtil.copyProperties(skuInfoEntity, searchSkuEsRestVO);
                    // 封装属性名不同的值
                    searchSkuEsRestVO.setSkuPrice(skuInfoEntity.getPrice());
                    searchSkuEsRestVO.setSkuImg(skuInfoEntity.getSkuDefaultImg());
                    //TODO 远程调用查询库存信息 - 是否有库存 - 后期更改为异步
                    R infoSkuStock = wareFeignClient.infoBySkuId(skuInfoEntity.getSkuId());
                    if (infoSkuStock.getCode() != 0) throw new RuntimeException("远程调用获取库存失败");
                    WareSkuRespVO wareSkuRespVO = infoSkuStock.getData(WareSkuRespVO.class);
                    if (wareSkuRespVO == null) throw new RuntimeException("远程调用获取库存失败");
                    if (wareSkuRespVO.getStock() == null) throw new RuntimeException("没有该商品库存信息");
                    searchSkuEsRestVO.setHasStock(wareSkuRespVO.getStock() == 0);
                    //TODO 未知元素
                    searchSkuEsRestVO.setHotScore(1L);
                    // 封装品牌信息
                    BrandEntity brandEntity = brandService.getById(skuInfoEntity.getBrandId());
                    if (brandEntity == null) throw new RuntimeException("没有找到对应的品牌信息");
                    searchSkuEsRestVO.setBrandName(brandEntity.getName());
                    searchSkuEsRestVO.setBrandImg(brandEntity.getLogo());
                    // 封装分类信息
                    CategoryEntity categoryEntity = categoryService.getById(skuInfoEntity.getCatalogId());
                    if (categoryEntity == null) throw new RuntimeException("没有找到对应的分类信息");
                    searchSkuEsRestVO.setCatalogName(categoryEntity.getName());
                    // 封装属性信息
                    searchSkuEsRestVO.setAttrs(attrs);
                    return searchSkuEsRestVO;
                }
        ).collect(Collectors.toList());

        // 向ES发送请求
        R saveSkuInfo = searchFeignClient.save(searchSkuEsRestVOS);
        if (saveSkuInfo.getCode() != 0) throw new RuntimeException("远程调用ES服务失败");

        boolean updatePublishStatus = this.lambdaUpdate()
                .set(SpuInfoEntity::getPublishStatus, SpuPublishStatusEnum.PUBLIC.getPublishStatus())
                .eq(SpuInfoEntity::getPublishStatus, SpuPublishStatusEnum.CREATE.getPublishStatus())
                .eq(SpuInfoEntity::getId, spuId)
                .update();

        // TODO 重新上架或者删除ES中数据
        if (!updatePublishStatus) throw new RuntimeException("更新商品上架状态失败");
    }

    /**
     * 根据skuId查询商品信息
     *
     * @param skuIds skuId列表
     * @return 商品信息
     */
    @Override
    public Map<Long, SpuInfoItemVO> getSpuInfoBySkuId(List<Long> skuIds) {
        Map<Long, SpuInfoItemVO> spuInfoItemVOMap = new HashMap<>();
        // 构建map
        for (Long skuId : skuIds) {
            // 获取sku信息
            SkuInfoEntity skuInfoEntity = skuInfoService.getById(skuId);
            // 获取商品信息
            SpuInfoEntity spuInfoEntity = this.lambdaQuery().eq(SpuInfoEntity::getId, skuInfoEntity.getSpuId()).one();
            // 获取品牌信息
            BrandEntity brandEntity = brandService.lambdaQuery().eq(BrandEntity::getBrandId, spuInfoEntity.getBrandId()).one();
            // 获取描述
            SpuInfoDescEntity spuInfoDescEntity = spuInfoDescService.lambdaQuery().eq(SpuInfoDescEntity::getSpuId, spuInfoEntity.getId()).one();
            // 构建spuInfoItemVO
            SpuInfoItemVO spuInfoItemVO = SpuInfoItemVO.builder()
                    .spuId(spuInfoEntity.getId())
                    .spuName(spuInfoEntity.getSpuName())
                    .price(spuInfoDescEntity.getDecript())
                    .spuBrand(brandEntity.getName())
                    .brandId(spuInfoEntity.getBrandId())
                    .categoryId(spuInfoEntity.getCatalogId())
                    .build();
            // 封装数据
            spuInfoItemVOMap.put(skuId, spuInfoItemVO);
        }


        return spuInfoItemVOMap;
    }

    /**
     * 上架商品 - 作废 逻辑问题
     *
     * @param spuId 商品id
     */
    public void upSpuInfoByIdVoidTwo(Long spuId) {
        // 获取商品信息
        SpuInfoEntity spuInfoEntity = this.getById(spuId);
        if (spuInfoEntity == null) throw new RuntimeException("没有找到对应的商品信息");
        if (spuInfoEntity.getPublishStatus() == SpuPublishStatusEnum.PUBLIC.getPublishStatus())
            throw new RuntimeException("商品已上架");

        // 1)、查出当前spuId对应的所有sku信息
        List<SkuInfoEntity> skuInfoEntities = skuInfoService.lambdaQuery().eq(SkuInfoEntity::getSpuId, spuInfoEntity.getId())
                .list();

        if (skuInfoEntities == null || skuInfoEntities.isEmpty())
            throw new RuntimeException("没有找到对应的sku信息");

        // 封装ES Sku信息
        List<SearchSkuEsRestVO> searchSkuEsRestVOS = skuInfoEntities.stream().map(
                skuInfoEntity -> {
                    SearchSkuEsRestVO searchSkuEsRestVO = new SearchSkuEsRestVO();
                    // 封装信息
                    // 属性对拷 先拷贝SkuInfoEntity与SearchSkuEsRestVO共有属性名
                    BeanUtil.copyProperties(skuInfoEntity, searchSkuEsRestVO);
                    // 封装属性名不同的值
                    searchSkuEsRestVO.setSkuPrice(skuInfoEntity.getPrice());
                    searchSkuEsRestVO.setSkuImg(skuInfoEntity.getSkuDefaultImg());
                    //TODO 远程调用查询库存信息 - 是否有库存 - 后期更改为异步
                    R infoSkuStock = wareFeignClient.infoBySkuId(skuInfoEntity.getSkuId());
                    if (infoSkuStock.getCode() != 0) throw new RuntimeException("远程调用获取库存失败");
                    WareSkuRespVO wareSkuRespVO = infoSkuStock.getData(WareSkuRespVO.class);
                    if (wareSkuRespVO == null) throw new RuntimeException("远程调用获取库存失败");
                    if (wareSkuRespVO.getStock() == null) throw new RuntimeException("没有该商品库存信息");
                    searchSkuEsRestVO.setHasStock(wareSkuRespVO.getStock() == 0);
                    //TODO 未知元素
                    searchSkuEsRestVO.setHotScore(1L);
                    // 封装品牌信息
                    BrandEntity brandEntity = brandService.getById(skuInfoEntity.getBrandId());
                    if (brandEntity == null) throw new RuntimeException("没有找到对应的品牌信息");
                    searchSkuEsRestVO.setBrandName(brandEntity.getName());
                    searchSkuEsRestVO.setBrandImg(brandEntity.getLogo());
                    // 封装分类信息
                    CategoryEntity categoryEntity = categoryService.getById(skuInfoEntity.getCatalogId());
                    if (categoryEntity == null) throw new RuntimeException("没有找到对应的分类信息");
                    searchSkuEsRestVO.setCatalogName(categoryEntity.getName());
                    // 封装属性信息
                    List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = skuSaleAttrValueService.lambdaQuery()
                            .eq(SkuSaleAttrValueEntity::getSkuId, skuInfoEntity.getSkuId())
                            .list();
                    if (skuSaleAttrValueEntities == null || skuSaleAttrValueEntities.isEmpty())
                        throw new RuntimeException("没有找到对应的属性信息");
                    List<SearchSkuEsRestVO.Attr> attrs = skuSaleAttrValueEntities.stream().map(
                            skuSaleAttrValueEntity -> {
                                SearchSkuEsRestVO.Attr attr = new SearchSkuEsRestVO.Attr();
                                attr.setAttrId(skuSaleAttrValueEntity.getAttrId());
                                attr.setAttrName(skuSaleAttrValueEntity.getAttrName());
                                attr.setAttrValue(skuSaleAttrValueEntity.getAttrValue());
                                return attr;
                            }
                    ).collect(Collectors.toList());
                    searchSkuEsRestVO.setAttrs(attrs);
                    return searchSkuEsRestVO;
                }
        ).collect(Collectors.toList());

        // 向ES发送请求
        R saveSkuInfo = searchFeignClient.save(searchSkuEsRestVOS);
        if (saveSkuInfo.getCode() != 0) throw new RuntimeException("远程调用ES服务失败");

        boolean updatePublishStatus = this.lambdaUpdate()
                .set(SpuInfoEntity::getPublishStatus, SpuPublishStatusEnum.PUBLIC.getPublishStatus())
                .eq(SpuInfoEntity::getPublishStatus, SpuPublishStatusEnum.CREATE.getPublishStatus())
                .eq(SpuInfoEntity::getId, spuId)
                .update();

        // TODO 重新上架或者删除ES中数据
        if (!updatePublishStatus) throw new RuntimeException("更新商品上架状态失败");
    }
}